#include <bits/stdc++.h>

using namespace std;
class Solution {
public:
    int maxProfit(vector<int>& prices) 
    {
        int ret = 0;
        int m = prices[0];
        for (int i = 1; i < prices.size(); ++i)
        {
            if (prices[i] < m)
            {
                m = prices[i];
            }
            ret = max(ret, prices[i] - m);
        }
        return ret;
    }
};